import java.util.concurrent.atomic.AtomicInteger;
public class Main {
    private static AtomicInteger totalSum = new AtomicInteger(0);
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            int sum = 0;
            for (int i = 1; i <= 10; i++) {
                sum += i;
            }
            totalSum.addAndGet(sum);
        });
        Thread t2 = new Thread(() -> {
            int sum = 0;
            for (int i = 11; i <= 20; i++) {
                sum += i;
            }
            totalSum.addAndGet(sum);
        });
        Thread t3 = new Thread(() -> {
            int sum = 0;
            for (int i = 21; i <= 30; i++) {
                sum += i;
            }
            totalSum.addAndGet(sum);
        });
        // 启动线程
        t1.start();
        t2.start();
        t3.start();
        // 等待所有线程完成
        t1.join();
        t2.join();
        t3.join();
        // 打印总和
        System.out.println("Total sum = " + totalSum.get());
    }
}
